package com.woniuxy.dao;

import com.woniuxy.pojo.ServerOrders;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

public interface ServerOrdersMapper {
    int deleteByPrimaryKey(Long id);

    int insert(ServerOrders record);

    int insertSelective(ServerOrders record);

    ServerOrders selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ServerOrders record);

    int updateByPrimaryKey(ServerOrders record);

    //pay_status = 0表示该订单未支付
    @Select("SELECT so.*,ss.subscribe_time sstime FROM server_orders so LEFT JOIN server_subscribe ss ON so.ser_id = ss.id WHERE so.id = #{soid} AND so.pay_status = 0")
    ServerOrders checkOrderAccomplish(Long soid);

    @Update("UPDATE server_orders SET end_time = #{date},pay_status = 1 WHERE id = #{soid}")
    void setEndTimeById(@Param("soid") Long soid,@Param("date") Date date);

    @Select("select * from server_orders where end_time <= #{preDate} and pay_status = 1")
    List<ServerOrders> timeoutAutocomplete(Date preDate);

    @Update("UPDATE server_orders SET pay_status = 3 WHERE id =#{id}")
    void updateServerOrderByOvertime(Long id);

    @Select("SELECT s.supplier_id id FROM server_orders so\n" +
            "LEFT JOIN server_subscribe ss\n" +
            "ON so.ser_id = ss.id\n" +
            "LEFT JOIN servers s\n" +
            "ON ss.server_id = s.id\n" +
            "WHERE so.id = #{id}")
    Long findPropertyIdByOrderId(Long id);
}